package com.dinzeer.slashblade_useful_addon.mixin;


import com.dinzeer.slashblade_useful_addon.config.Config;
import mods.flammpfeil.slashblade.ability.StunManager;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.effect.MobEffects;
import net.minecraft.world.entity.LivingEntity;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(StunManager.class)
public abstract class StunManagerMixin {

    @Inject(
            method = "setStun(Lnet/minecraft/world/entity/LivingEntity;J)V",
            at = @At("HEAD"),
            cancellable = true,
            remap = false
    )
    private static void applyEffects(LivingEntity target, long duration, CallbackInfo ci) {

        boolean shouldCancel = Config.ds;

        if (shouldCancel) {
            ci.cancel();
                target.addEffect(new MobEffectInstance(
                        MobEffects.MOVEMENT_SLOWDOWN,
                        100,
                        2,
                        false, // 无粒子效果
                        true   // 显示图标
                ));

        }
    }
}